package com.aounhui.productor.factory;

import com.aounhui.common.utils.UUIDUtil;
import com.aounhui.productor.controller.CommodityController;
import com.aounhui.productor.entity.Commodity;
import com.aounhui.productor.entity.CommodityFactory;
import com.aounhui.productor.mapper.CommodityFactoryMapper;
import com.aounhui.productor.mapper.CommodityMapper;
import com.aounhui.productor.service.CommodityService;
import com.netflix.discovery.converters.Auto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author aounhui
 * @version 1.0
 * @date 2021/6/29 14:36
 * @description
 */
@Slf4j
@Component
public class ProductorFactory {

    @Autowired
    private CommodityFactoryMapper commodityFactoryMapper;
    @Autowired
    private CommodityService commodityService;

    public void productor(String commodityName) {
        log.info("====={}工厂收到生产消息，生产开始======", commodityName);
        CommodityFactory commodityFactory = commodityFactoryMapper.selectByPrimaryKey(commodityName);
        log.info("{}产品，生产间隔{}分钟", commodityFactory.getName(), commodityFactory.getCreateSchedule());
        long creatTime = commodityFactory.getCreateSchedule() * 60 * 1000;
        try {
            Thread.sleep(creatTime);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        commodityService.commodityCreater(commodityFactory);
        log.info("{}生产线生产出一个产品", commodityFactory.getName());
    }

}
